package com.ruoyi.map.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.manager.pms.domain.entity.PmsBrandAttention;
import com.cyl.manager.pms.mapper.PmsBrandAttentionMapper;
import com.cyl.manager.ums.domain.entity.UserInfo;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.framework.config.LocalDataUtil;
import com.ruoyi.map.domain.PmsBrand;
import com.ruoyi.map.mapper.PmsBrandMapper;
import com.ruoyi.map.service.IPmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sangsijing
 * @since 2025/5/8 19:01
 */
@Service
public class PmsBrandServiceImpl implements IPmsBrandService {

    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    @Autowired
    private PmsBrandAttentionMapper brandAttentionMapper;
    @Override
    public PmsBrand getDetails(Long brandId) {

       return pmsBrandMapper.getDetails(brandId);
    }

    @Override
    public PmsBrand brandProductDetail(Long brandId) {
        PmsBrand details = pmsBrandMapper.getDetails(brandId);

        //获取关注
        UserInfo member = (UserInfo) LocalDataUtil.getVar(Constants.MEMBER_INFO);
        PmsBrandAttention pmsBrandAttention = new PmsBrandAttention();
        pmsBrandAttention.setBrandId(brandId);
        pmsBrandAttention.setUserId(member.getId());
        List<PmsBrandAttention> pmsBrandAttentions = brandAttentionMapper.selectByEntity(pmsBrandAttention);
        if (pmsBrandAttentions.isEmpty()) {
            details.setFollower("0");
        } else {
            details.setFollower(pmsBrandAttentions.get(0).getFollower());
        }

        //获取粉丝数
        QueryWrapper<PmsBrandAttention> queryWrapper =  new QueryWrapper<>();
        queryWrapper.eq("brand_id", brandId);
        queryWrapper.eq("follower", "1");
        Integer integer = brandAttentionMapper.selectCount(queryWrapper);
        details.setCount(integer);

        return details;
    }
}
